$(document).ready(function(e) {
	
var r = $("#search_input")[0];
if (r) {
	Wind.use("autocomplete",function(){
		$.autocomplete(r, {
			url: "/product/ajax",
			matchCase: false,
			matchContains: true,
			cacheLength: 10,
			width: 208,
			enterPressCallBack: function() {
				 $("#search_submit").trigger("click");
			}				
		})
	})
}

$("#search_submit").click(function() {	
	var  kw = $("#search_input");
	if(kw.val().trim().length == 0 ){kw.focus(); return}
	location.href = "/product/search?keyword="+ kw.val();
});

function c(){
	var b = $('#brand_content').data('brand');	
	$.get('/index/aj_get',{brand:b},function(msg){
			if(msg.status == 1){v(msg.data,b)}
			else{$('#brand_content').html('<p style="padding:50px; text-align:center; font-size:14px;">\u6682\u65e0\u7ed3\u679c\u3002</p>')}
		});			
}

function v(json,brand){
	var temp = JSON.parse(json);
	var xhtml = '';
	$.each(temp,function(i,e){			
		if( brand == 0 ){				
			xhtml += "<li><a class=\"item\" href=\"/item/"+e.id+".html\" title=\""+e.pname+"\" >"+"<img src=\""+e.avatar+"\" /><div><h2>"+e.pname+"</h2><div class=\"hover\"><p>最高回收价：￥"+e.price+"</p><span class=\"btn-s\">去估价</span></div></div></a></li>";
		}
		else{			
			if(i==9){
				xhtml += "<li><a class=\"all\"  href=\"/brand/"+brand+".html\">查看更多机型</a></li>";	
			}else{
				xhtml += "<li><a class=\"item\" href=\"/item/"+e.id+".html\" title=\""+e.pname+"\" >"+"<img src=\""+e.avatar+"\" /><div><h2>"+e.pname+"</h2><div class=\"hover\"><p>最高回收价：￥"+e.price+"</p><span class=\"btn-s\">去估价</span></div></div></a></li>";				
			}
		}		
	})
	$('#brand_content').html(xhtml);	
}

var b_list = $("#brand_list").find('li');
	b_list.on("click",function(){
		var t = $(this);
		t.attr("class","brand_selected").siblings(".brand_selected").removeAttr("class");
		var p1 = t.find('div').data('brand');
		var p2 = $("#brand_content").data('brand');
		if(p1 != p2){
			$("#brand_content").data('brand',p1)
			c();
		}		
	});	
c();

	$(".scrollLoading").attr('src','/statics/images/loading.gif');
	Wind.use("scrollLoading",function(){
		$(".scrollLoading").scrollLoading();
	});
	Wind.css('Swiper');
	Wind.use("Swiper",function(){
		new Swiper('#banner_box', {
          speed: 500,
          autoplay: 3000,
          paginationClickable: true,
          autoplayDisableOnInteraction: false,
          loop: true
        });
	});
});